pp108 : Setting Data For Models

Setting Data For Models

This topic describes the setting of data from various sources for models.

You can bind data to controls using the following:

  • using the putData() method
  • using Process APIs

Setting data using the putData() method

When the reset() or getDataset() methods are used to set data, the data is retrieved and bound to the respective controls. However, if data is present as XML, use the putData() method to set the XML to the data model.

After setting the XML data for the model, you can render the data to controls using the following:

newModel.putData(request, true);

Setting data using Process APIs

Sometimes, as part of a workflow, manual intervention is needed, which necessitates the display of an interface for decision making. In such a workflow, you can use XForms as screens that display options for decision making. To use an XForm in a workflow, save it and publish it to the organization. You can drag the published XForm to a business process model to use it in the workflow.

To enable the participation of controls in a workflow, Process Platform XForms provides a set of process APIs for the controls, at run time. It is possible to pass data through a workflow by following certain pre-defined data formats. You can use process APIs to pass data as follows:

  • By passing parameters: Parameters can be passed to an XForm using the <request> node. The <request> node can be created inside the <data> node in the application definition.
    The below sample application definition retrieves data from the EmployeesModel model.
    <data>
        <forminputdata xmlns="http://schemas.cordys.com/1.0/xforms/processapi">
            <EmployeesModel type="get">
                <GetEmployeesObject xmlns="http://schemas.cordys.com/NorthwindMetadata/Employees">
                    <EmployeeID>5</EmployeeID>
                </GetEmployeesObject>
            </EmployeesModel>
        </forminputdata>
    </data>
    

    Attention
    The following way of passing parameter is now DEPRECATED. Please use as given in the example above.

    <Application>
        <url>/Employees.caf</url>
        <id>uniqueid</id>
        <frame>main</frame>
        <description>Employees</description>
        <caption>Employees</caption>
        <data>
            <request model="EmployeesModel">
                <dataset type="get">
                    <EmployeeID>5</EmployeeID>
                </dataset>
            </request>
        </data>
    </Application>
    

    Where,

    • The model attribute is mandatory and refers to the name of the model from which data is to be retrieved.
    • The type property refers to the type of method request. The method request can be of the type - get, next, or previous.
  • By passing data: You can also pass data directly to a specific model in an XForm. The data will be picked by the model, and rendered into a control, according to set references.
    In the following example, the <data> node inside application definition is set for fifth Employee.
    <data>
        <forminputdata xmlns="http://schemas.cordys.com/1.0/xforms/processapi">
            <EmployeesModel type="put">
                <GetEmployeesObjectResponse xmlns="http://schemas.cordys.com/NorthwindMetadata/Employees">
                    <tuple>
                        <old>
                            <Employees>
                                <EmployeeID>5</EmployeeID>
                                <FirstName>Steve</FirstName>
                                <LastName>Buchanan</LastName>
                            </Employees>
                        </old>
                    </tuple>
                </GetEmployeesObjectResponse>
            </EmployeesModel>
        </forminputdata>
    </data>
    

    Attention
    The following ways of passing data is now DEPRECATED. Please use as given in the example above.

    <data>
        <request model="EmployeesModel">
            <EmployeesResponse>
                <tuple>
                    <old>
                        <Employees>
                            <EmployeeID>5</EmployeeID>
                        </Employees>
                    </old>
                </tuple>
            </EmployeesResponse>
        </request>
    </data>
    

    In the above example, if the optional attribute create is set to true on the <request> node, then the specified model, EmployeesModel, will be created and data set on it.
    The following example demonstrates passing data based on a business object name:

    <data>
    	<Request>
    		<Employees namespace="http://schemas.cordys.com/1.0/demo/northwind">
    			<PutData>
    				<GetEmployeesResponse>
    					<tuple>
    						<old>
    							<Employees>
    								<EmployeeID>2</EmployeeID>
    							</Employees>
    						</old>
    					</tuple>
    				</GetEmployeesResponse>
    			</PutData>
    		</Employees>
    	</Request>
    </data>

    In the above example, a <request> tag containing the business object name is used, by which dependency on model name is removed.

    It is also possible to send initial data values for free-form controls in an XForm, as displayed in the following example. Here, the value '5' is passed to the <input1> input control in the <data> node.

    <data>
        <forminputdata xmlns="http://schemas.cordys.com/1.0/xforms/processapi">
            <freeformcontrols>
                <input1>5</input1>
            </freeformcontrols>
        </forminputdata>
    </data>
    

    Attention
    The following ways of sending initial data for free-form controls is now DEPRECATED. Please use as given in the example above.

    <data>
        <freeformdata>
            <input1>5</input1>
        </freeformdata>
    </data>
    

    Attention
    Passing an action to set data is now DEPRECATED.
    By passing an action: Some scenarios in workflow processes demand XForms to open in a specific action mode, for example creating a new registration form requires the XForm to open in the Insert mode.
    The following sample shows how to open the Employees data table or group in the insert mode.

    <data>
        <Action>
            <Employees namespace="http://schemas.cordys.com/1.0/demo/northwind">
                <Insert/>
            </Employees>
        </Action>
    </data>
    

Related reference

putData()
Model